package sanrenxing.dayEnd.backRepertoryTotal.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.TradingSeatDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TradingSeat;
import sanrenxing.dayEnd.backRepertoryTotal.service.TradingSeatBiz;

import java.util.HashMap;
import java.util.List;

@Service("tradingSeatBiz")
public class TradingSeatBizImpl implements TradingSeatBiz {
    @Autowired
    private TradingSeatDao tradingSeatDao;
    /**
     * 将基金实体添加数据库基金表中
     *
     * @param tradingSeat 基金对象
     * @return 0:添加失败,1:添加成功
     */
    @Override
    public int add(TradingSeat tradingSeat) {
        return tradingSeatDao.add(tradingSeat);
    }

    /**
     * 从表中根据基金编号字符串删除一行数据
     * @param seatId 基金编号字符串
     * @return 删除影响的行数(0 : 删除失败, 1 : 删除成功)
     */
    @Override
    public int delete(String seatId) {
        //判断是否为批量删除
        if(seatId.contains(",")){
            //对编号按“，”分割
            String[] strs=seatId.split(",");
            //循环删除
            for(String str:strs){
                //调用方法删除
                tradingSeatDao.delete(Integer.parseInt(str));
            }
            //返回1
            return 1;
        }
        return tradingSeatDao.delete(Integer.parseInt(seatId));
    }

    /**
     * 修改数据到foundation表
     *
     * @param tradingSeat 员工对象
     * @return 0:修改失败,1:修改成功
     */
    @Override
    public int update(TradingSeat tradingSeat) {
        return tradingSeatDao.update(tradingSeat);
    }

    /**
     * 查询所有数据
     *
     * @param tradingSeat
     * @param row
     * @param page
     * @return
     */
    @Override
    public List<TradingSeat> queryAll(TradingSeat tradingSeat, int row, int page) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("tradingSeat",tradingSeat);
        map.put("start",page);
        map.put("end",(page+row));
        return tradingSeatDao.queryAll(map);
    }

    /**
     * 按条件统计记录数
     *
     * @param tradingSeat 统计条件
     * @return 记录行数据
     */
    @Override
    public int count(TradingSeat tradingSeat) {
        return tradingSeatDao.count();
    }
}
